var gd_id_status = false, gd_password_status = false;
var gd_id, gd_password;
var aotuLogin;
$("#gd_id").blur(function () {
    gd_id_check();
});

function gd_id_check() {
    gd_id = $.trim($("#gd_id").val());
    if (gd_id.length > 0) {
        $.ajax({
            // async: false,
            type: "get",
            data: {gd_id: gd_id},
            url: "findUserById.do",
            success: function (data) {
                if (data == "true") {
                    $("#gd_id_checkInfo").css("color", "green");
                    $("#gd_id_checkInfo").text("用户名可用！");
                    gd_id_status = true;
                } else if (data == "false") {
                    $("#gd_id_checkInfo").css("color", "red");
                    $("#gd_id_checkInfo").text("用户不存在！");
                    gd_id_status = false;
                }
            }
        })
    } else {
        $("#gd_id_checkInfo").css("color", "red");
        $("#gd_id_checkInfo").text("请输入工号！");
        gd_id_status = false;
    }
}

function gd_password_check() {
    gd_password = $.trim($("#gd_password").val());
    if (gd_password.length == 0) {
        $("#gd_password_checkInfo").css("color", "red");
        $("#gd_password_checkInfo").text("请输入密码！");
        gd_password_status = false;
    } else {
        $("#gd_password_checkInfo").text("");
        gd_password_status = true;
    }
}

//表单提交时校验
function checkLogin() {
    gd_id_check();
    gd_password_check();
    var status = false;
    if (gd_password_status && gd_id_status) {
        if ($("#autoLoginFlag").prop("checked")){
            aotuLogin = "on";
        }else{
            aotuLogin = null;
        }

        $.ajax({
            type: "post",
            dataType: "text",
            data: {gd_id: gd_id, gd_password: gd_password,autoLoginFlag:aotuLogin},
            url: "loginUser.do",
            timeout: 5000,
            async: false,//同步加载
            success: function (data) {
                if (data == "false") {
                    $("#gd_password_checkInfo").text("密码不正确,请重新输入！");
                    status = false;
                } else {
                    $("#info").css("color", "green");
                    $("#info").text("登录成功！");
                    status = true;
                }
            },
            /*移动端需要考虑网络问题*/
            error: function () {
                $("#info").css("color", "red");
                $("info").text("登录请求超时，请重试！")
            }
        });
    }
    return status;
}

